package selenium.demo;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import static java.lang.Thread.sleep;

/**
 * @Author quan
 * @Description 浏览器的前进和后退
 * @Date 2023/8/14 12:26
 */
public class Demo9_BrowserBackForward {
    public static void main(String[] args) throws InterruptedException {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver = new ChromeDriver(options);
        webDriver.get("https://www.baidu.com/");
        //在浏览器的搜索框输入文字”软件测试“
        webDriver.findElement(By.cssSelector("#kw")).sendKeys("软件测试");
        //点击“百度一下”按钮
        webDriver.findElement(By.cssSelector("#su")).click();
        //浏览器回退到初始页面
        sleep(5000);
        webDriver.navigate().back();
        //再次前进到“软件测试”页面
        sleep(5000);
        webDriver.navigate().forward();
        //刷新
        webDriver.navigate().refresh();
    }
}
